﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CdcSoftware.Pivotal.Applications.Core.Client;
using CdcSoftware.Pivotal.Engine.Client.ClientTasks.Attributes;
using CdcSoftware.Pivotal.Engine.Client.Services.Interfaces;
using CdcSoftware.Pivotal.Engine.UI.Forms;
using CdcSoftware.Pivotal.Applications.Core.Common;
using System.Windows.Forms;

namespace Pcm.Retail.Client.FormTasks.CommandHandlers
{
    public class RESalesCommandHandlers: CommandClientTask
    {
        /// <summary>
        /// On click of Refund task item.
        /// </summary>
        /// <history>
        /// Revision   Date        Author  Description
        /// 6.0.12.1   19/04/2013  DS      Initial Version
        /// </history>
        [ClientTaskCommand]
        public virtual void RefundSalesCommand()
        {
            try
            {
                //DS: 19042013 - For Offline if the POS is not master POS, then don't allow to create new Sale.
                if (SystemClient.SystemInformation.IsMobile && !Globals.IsMasterPOS)
                    PivotalMessageBox.Show("This feature is not available Offline when POS is not Master POS.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                {
                    ICenterContentView centerContent = (ICenterContentView)ClientContext.ClientAPIService.GetActiveContentObject();

                    if (centerContent is IFormView)
                    {
                        RESales sales = new RESales();
                        sales.RefundStub();
                    }
                    else
                    {
                        //If centerContent is SearchView or ActiveSearchPages
                        TransitionPointParameter tParams = new TransitionPointParameter();
                        tParams.Construct();
                        tParams.SetUserDefinedParameter(3, "Refund");

                        Globals.NewForm("RE_Sale – Walk In", tParams.ParameterList, ActionTargetWindow.Current);
                    }
                }
            }
            catch (Exception exc)
            {
                Globals.HandleException(exc);
            }
        }

        /// <summary>
        /// On click of New Sale task item.
        /// </summary>
        /// <history>
        /// Revision   Date        Author  Description
        /// 6.0.12.1   19/04/2013  DS      Initial Version
        /// </history>
        [ClientTaskCommand]
        public virtual void NewSalesCommand()
        {
            try
            {
                //DS: 19042013 - For Offline if the POS is not master POS, then don't allow to create new Sale.
                if (SystemClient.SystemInformation.IsMobile && !Globals.IsMasterPOS)
                     PivotalMessageBox.Show("New Sale is not available Offline when POS is not Master POS.", MessageBoxButtons.OK,MessageBoxIcon.Information);
                else
                    Globals.NewForm("RE_Sale – Walk In", null);
            }
            catch (Exception exc)
            {
                Globals.HandleException(exc);
            }
        }
    }
}
